package twel.probenprophet.helden.heroes.helden5.jaxb;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import twel.probenprophet.base.enums.Attribute;

public class AttributeMapEntry {

	private Attribute attribute;
	private Integer value;

	public AttributeMapEntry() {
	}

	public AttributeMapEntry(Attribute attribute, Integer value) {
		this.attribute = attribute;
		this.value = value;
	}

	@XmlAttribute(name = "name")
	@XmlJavaTypeAdapter(value = AttributeAdapter.class)
	public Attribute getAttribute() {
		return attribute;
	}

	@XmlAttribute(name = "value")
	public Integer getValue() {
		return value;
	}

	static class AttributeAdapter extends XmlAdapter<String, Attribute> {

		@Override
		public Attribute unmarshal(String string) throws Exception {
			return Attribute.byGermanName(string);
		}

		@Override
		public String marshal(Attribute attribute) throws Exception {
			return attribute.getGermanName();
		}

	}
}
